package top.superflow.flow.config.parse.center

import top.superflow.exception.Exceptable
import top.superflow.flow.config.parse.impl.MapperConfigParser
import top.superflow.flow.mapper.MapperConfig

class MapperConfigParserCenter private  extends ParserCenter[MapperConfig, MapperConfigParser] with Exceptable{

  def getParser(mapperConfig : MapperConfig) : MapperConfigParser = {
    if(mapperConfig == null){
      throwRequestUnsupportedException("The resource config should not be null!")
    }
    val mapperType = mapperConfig.getMapperType

    val mapperParser = this.getParser(mapperType)
    if(mapperParser == null){
      throwRequestUnsupportedException("There is no registered parser for the resource type ", mapperType)
    }

    mapperParser
  }

}

object MapperConfigParserCenter {
  private final val instance = new MapperConfigParserCenter

  def getInstance = instance
}
